//
//  ConnectionsController.h
//  Genesis
//
//  Created by Kristoffer Andersen on 13/03/09.
//  Copyright 2009 Kristoffer Andersen. All rights reserved.
//
//  This file is part of Genesis.
//  
//  Genesis is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//  
//  Genesis is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with Genesis.  If not, see <http://www.gnu.org/licenses/>.

#import <Cocoa/Cocoa.h>
#import "GConnection.h"
#import "GProgressIndicatorCell.h"


@interface ConnectionsController : NSObject {
	
	NSObject *myDelegate;
	
	IBOutlet NSTableView *connectionTable;
	IBOutlet NSWindow *newConnWindow;
	IBOutlet NSButton *connSheetSaveButton;
	IBOutlet NSButton *connSheetCancelButton;
	
	IBOutlet NSTextField *connNameField;
	IBOutlet NSTextField *tunnelHostField;
	IBOutlet NSTextField *serviceTypeField;
	IBOutlet NSTextField *tunnelUsernameField;
	IBOutlet NSTextField *forwardHostField;
	IBOutlet NSTextField *forwardPortField;
	IBOutlet NSTextField *localHostField;
	IBOutlet NSTextField *localPortField;
	IBOutlet NSTextField *serviceRecordField;
	IBOutlet NSButton *useBonjourButton;
	
	GConnection *selectedConnection; 
	NSMutableArray *connections;
	
	IBOutlet NSButtonCell *tableConnectButton;
	IBOutlet NSButtonCell *tableConsoleButton;
	IBOutlet NSButtonCell *tableSettingsButton;
	
	IBOutlet NSTextView *consoleView;
	IBOutlet NSPanel *consolePanel;
	NSWindowController *consoleWindowController;

    IBOutlet NSWindow *passwordDialog;
    IBOutlet NSSecureTextField *passwordField;
    GConnection *passwordConnection;
    NSRecursiveLock *passwordLock;
    IBOutlet NSTextField *passwordConnectionName;
    IBOutlet NSTextField *passwordUserName;
    IBOutlet NSTextField *passwordHostName;
	
}
-(void) unlockPassword;

-(IBAction)addConnButton:(id)sender;
-(IBAction)removeConnButton:(id)sender;
-(IBAction)editConnButton:(id)sender;
-(IBAction)cancelAddConnButton:(id)sender;
-(IBAction)saveAddConnButton:(id)sender;
-(IBAction) passwordEntered:(id)sender;
-(void)saveAllConnectionsToDisk;

-(IBAction)tableConnectButton:(id)sender;
-(IBAction)tableConsoleButton:(id)sender;
-(IBAction)tableSettingsButton:(id)sender;

////////////////////////////////////////////////////////////////
//// TableData Source protocol

-(int)numberOfRowsInTableView:(NSTableView *)aTableView;
-(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;

////////////////////////////////////////////////////////////////
//// Accessors for Connection Options

-(NSString *)connectionName;
-(NSString *)tunnelHost;
-(NSString *)forwardHost;
-(unsigned int)forwardPort;
-(NSString *)localHost;
-(unsigned int)localPort;
-(NSString *)serviceType;
-(NSString *)serviceName;
-(NSString *)tunnelUsername;
-(bool)useBonjour;

-(void)setConnectionName:(NSString *)newConnectionName;
-(void)setTunnelHost:(NSString *)newTunnelHost;
-(void)setForwardHost:(NSString *)newForwardHost;
-(void)setForwardPort:(unsigned int)newForwardPort;
-(void)setLocalHost:(NSString *)newLocalHost;
-(void)setLocalPort:(unsigned int)newLocalPort;
-(void)setServiceType:(NSString *)newServiceType;
-(void)setServiceName:(NSString *)newServiceName;
-(void)setTunnelUsername:(NSString *)newTunnelUsername;
-(void)setUseBonjour:(bool)newUseBonjour;

-(void)reloadConnWindowFields;

////////////////////////////////////////////////////////////////
//// Delegate specific

-(void)setDelegate:(id)theDelegate;
-(id)delegate;

-(void)terminateAllOpenConnections;
-(BOOL)hasOpenConnections;

-(NSString*)requestPasswordForConnection:(GConnection*)connection;

@end
